﻿namespace YunQue.WebApi.Controllers.System
{
    /// <summary>
    /// 用户接口
    /// </summary>
    [ApiExplorerSettings(GroupName = "User")]
    public class UserController : BaseController
    {
        private readonly UserService _userService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userService"></param>
        public UserController(UserService userService)
        {
            _userService = userService;
        }

        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<ApiPageResultModel<UserInfo>> GetListAsync([FromBody] ApiPageRequestModel<UserListRequest> request)
        {
            return await _userService.GetListAsync(request).ConfigureAwait(false);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("get")]
        public async Task<UserInfo> GetAsync(string id)
        {
            return await _userService.GetUserByIdAsync(id).ConfigureAwait(false);
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<string> AddAsync([FromBody] UserInfo request)
        {
            return await _userService.AddUserAsync(request).ConfigureAwait(false);
        }

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("update")]
        public async Task<bool> UpdateAsync([FromBody] UserInfo request)
        {
            return await _userService.UpdateUserInfoAsync(request).ConfigureAwait(false);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task<bool> DeleteAsync(string id)
        {
            return await _userService.DeleteUserByIdAsync(id);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpPost("update_password")]
        public async Task<bool> UpdatePasswordAsync(string password)
        {
            return await _userService.UpdatePasswordAsync(password);
        }
    }
}
